package hashmap01;

import java.util.HashMap;
import java.util.HashSet;

/*
*  boolean isEmpty()
          如果map中没有键值对返回true，如果有键值对返回false
* boolean containsKey(Object key)
          判断指定的key在map中是否存在，存在返回true，不存在返回false
* V remove(Object key)
          根据key移除map中的键值对，返回该key对应的value
* */
public class HashMapDemo02 {
    public static void main(String[] args) {
        method01();
        method02();
        method03();

    }

    private static void method03() {
        HashMap<Integer, String> hm3 = new HashMap<>();
        hm3.put(123,"张三");
        hm3.put(456,"李四");
        hm3.put(789,"王五");

        String str = hm3.remove(789);
        System.out.println(str); // 王五
        System.out.println(hm3); // {456=李四, 123=张三}

        System.out.println(hm3.remove(13)); // null
        System.out.println(hm3);  // {456=李四, 123=张三}
    }

    private static void method02() {
        HashMap<Integer, String> hm2 = new HashMap<>();
        hm2.put(123,"张三");
        hm2.put(456,"李四");
        hm2.put(789,"王五");
        System.out.println(hm2.containsKey(456)); // true
        System.out.println(hm2.containsKey(13)); //  false
    }

    private static void method01() {
        HashMap<Integer, String> hm = new HashMap<>();
        hm.put(123,"张三");
        hm.put(456,"李四");
        hm.put(789,"王五");
        System.out.println(hm.isEmpty());// false

        hm.clear();
        System.out.println(hm.isEmpty()); // true
    }
}
